﻿using MaterialDesignThemes.Wpf;
using ReportMealManagementSystem.MyControl.ViewModel;
using ReportMealManagementSystem.Entity;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Animation;

namespace ReportMealManagementSystem
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Fluent.RibbonWindow
    {
        bool MenuClosed = false;

        public MainWindow()
        {
            InitializeComponent();

            var menuRegister = new List<SubItem>();
            if (Global.MealUser.isManager == true)
            {
                menuRegister.Add(new SubItem("公司设置", PackIconKind.Company, null, new CompanySetting()));
                menuRegister.Add(new SubItem("区域设置", PackIconKind.Arena, null, new DistrictSetting()));
                menuRegister.Add(new SubItem("评价项目设置", PackIconKind.Approval, null, new EvaluationContentSetting()));
            }
            if ((Global.MealUser.isAdmin == true && (Global.MealUser.company.VersionNumber == "3" || Global.MealUser.company.VersionNumber == "4" || Global.MealUser.company.VersionNumber == "5")) || Global.MealUser.isManager == true)
            {
                menuRegister.Add(new SubItem("食堂设置", PackIconKind.Dining, null, new DiningHallSetting()));
                menuRegister.Add(new SubItem("餐点设置", PackIconKind.Meat, null, new MealTimeSetting()));
                menuRegister.Add(new SubItem("通讯录", PackIconKind.Book, null, new AddressBookSetting()));
                menuRegister.Add(new SubItem("属性设置", PackIconKind.Nature, null, new AttributeSetting()));
                menuRegister.Add(new SubItem("菜品分类", PackIconKind.Class, null, new DishesClassSetting()));
                menuRegister.Add(new SubItem("菜品设置", PackIconKind.Food, null, new DishesSetting()));
            }
            if(Global.MealUser.isManager == true)
            {
                menuRegister.Add(new SubItem("系统设置", PackIconKind.Settings, null, new SystemSetting()));
            }
            var item0 = new ItemMenu("基础信息", menuRegister, PackIconKind.SettingsApplications);

            var menuSchedule = new List<SubItem>();
            if ((Global.MealUser.IsFinace == true && (Global.MealUser.company.VersionNumber == "4" || Global.MealUser.company.VersionNumber == "5")) || Global.MealUser.isManager == true)
            {
                menuSchedule.Add(new SubItem("用户充值", PackIconKind.PaymentSettings, null, new UserRecharge()));
                menuSchedule.Add(new SubItem("用户账户明细", PackIconKind.UserDetails, null, new MealUserStoredValue()));
                menuSchedule.Add(new SubItem("充值记录", PackIconKind.PaymentOnDelivery, null, new UserStoredValueRecord()));
                menuSchedule.Add(new SubItem("消费记录", PackIconKind.PaymentOnDelivery, null, new UserXpenseTracker()));
            }
            var item1 = new ItemMenu("储值", menuSchedule, PackIconKind.Payment);

            var menuAnnouncement = new List<SubItem>();
            menuAnnouncement.Add(new SubItem("发布公告", PackIconKind.Announcement, null, new Announce()));
            menuAnnouncement.Add(new SubItem("公告管理", PackIconKind.AnnouncementOutline, null, new AnnounceManage()));
            var item2 = new ItemMenu("公告", menuAnnouncement, PackIconKind.Announcement);

            var menuReports = new List<SubItem>();
            if (Global.MealUser.isAdmin == true || Global.MealUser.isManager == true)
            {
                menuReports.Add(new SubItem("报餐统计（每天）", PackIconKind.FileReport, null, new AllMealStatisticsReportOneDay()));
                if (Global.MealUser.company.VersionNumber == "3" || Global.MealUser.company.VersionNumber == "4" || Global.MealUser.company.VersionNumber == "5" || Global.MealUser.isManager == true)
                {
                    menuReports.Add(new SubItem("报餐统计（全部）", PackIconKind.FileReport, null, new AllMealStatisticsReport()));
                }
                menuReports.Add(new SubItem("报餐明细（每天）", PackIconKind.UserDetails, null, new AllReportMealDetailOneDay()));
                if (Global.MealUser.company.VersionNumber == "3" || Global.MealUser.company.VersionNumber == "4" || Global.MealUser.company.VersionNumber == "5" || Global.MealUser.isManager == true)
                {
                    menuReports.Add(new SubItem("报餐明细（全部）", PackIconKind.UserDetails, null, new AllReportMealDetail()));
                    menuReports.Add(new SubItem("点菜排行", PackIconKind.FileReport));
                }
                if (Global.MealUser.company.VersionNumber != "1")
                {
                    menuReports.Add(new SubItem("评价报告单", PackIconKind.FileReport));
                }
                menuReports.Add(new SubItem("用餐统计", PackIconKind.FileReport));
                menuReports.Add(new SubItem("用餐明细", PackIconKind.UserDetails));
            }
            var item3 = new ItemMenu("报表", menuReports, PackIconKind.FileReport);

            Menu.Children.Add(new UserControlMenuItem(item0, this));
            Menu.Children.Add(new UserControlMenuItem(item1, this));
            Menu.Children.Add(new UserControlMenuItem(item2, this));
            Menu.Children.Add(new UserControlMenuItem(item3, this));
        }

        private void RibbonWindow_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void btnMenu_Click(object sender, RoutedEventArgs e)
        {
            if (MenuClosed)
            {
                Storyboard openMenu = (Storyboard)btnMenu.FindResource("OpenMenu");
                openMenu.Begin();
            }
            else
            {
                Storyboard closeMenu = (Storyboard)btnMenu.FindResource("CloseMenu");
                closeMenu.Begin();
            }

            MenuClosed = !MenuClosed;
        }

        internal void SwitchScreen(object sender)
        {
            var screen = ((UserControl)sender);
            gContent.Children.Clear();
            if (screen != null)
            {
                gContent.Children.Add(screen);
            }
        }

        private void Label_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            gContent.Children.Clear();
        }
    }
}
